class_name StateMachine extends Resource

@export var states : Array[State]
@export var current_state: State = null
var character : Character

func initialize(owner: Character):
	character = owner
	if states.size():
		current_state = states[0] # 默认数组中第一个状态为初始状态
		current_state.enter()
	for state in states:
		state.state_machine = self
		state.character = character

func travel_to(state_name: String):
	for state in states:
		if state.state_name == state_name:
			current_state.exit()
			current_state = state
			current_state.enter()
